package com.china08.yxyapi.api.manage.sch.office.cookbook;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.cookbook.CookBook;
import com.china08.yxyapi.entity.mg.cookbook.CookBook.Meal;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.cookbook.YxySchManageCookbookRepository;

/**
 * 每周食谱--管理员--查看每周食谱
 * 
 * @author LiuWeidong
 *
 */

@CrossOrigin
@RestController
public class YxySchManagerCookbookSrhController extends YxyApiBaseController {

    @Autowired
    private YxySchManageCookbookRepository yxySchManageCookbookRepository;

    @RequestMapping(value = "/api_yw/manage/sch/offic/cookBook/YxySchManageCookbookSrh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel,
            RespModel respModel) {
        String schoolId = getProfile(request, response).getSchoolId();
        Integer weekId = reqModel.weekId;
        CookBook cookBook = yxySchManageCookbookRepository.findBySchoolIdAndWeekId(schoolId, weekId);

        // 转存到model
        RespModel model = new RespModel();
        if (cookBook != null) {
            model.id = cookBook.getId();
            model.schoolId = cookBook.getSchoolId();
            model.schoolName = cookBook.getSchoolName();
            model.weekName = cookBook.getWeekName();
            model.breakfast = cookBook.getBreakfast();
            model.breakfastCakes = cookBook.getBreakfastCakes();
            model.lunch = cookBook.getLunch();
            model.lunchCakes = cookBook.getLunchCakes();
            model.dinner = cookBook.getDinner();
        }
        return model;

    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiReqModel {
        // 星期ID,1-7
        public Integer weekId;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {
        // ID
        public String id;
        // 学校ID
        public String schoolId;
        // 学校名称
        public String schoolName;
        // 中文：星期一--星期七
        public String weekName;
        // 早餐
        public Meal breakfast;
        // 早点
        public Meal breakfastCakes;
        // 午餐
        public Meal lunch;
        // 午点
        public Meal lunchCakes;
        // 晚餐
        public Meal dinner;
    }

}
